// -*- c++ -*-

#version 330 core

layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inColor;
layout (location = 2) in vec3 inNormal;
layout (location = 3) in vec2 inTexCoords;

out vec3 vColor;
out vec2 texCoords;

struct SceneLighting
{
  vec4 ambient;
  vec3 light_pos;
  // vec4 diffuse_dir;
};

uniform mat4 m_proj;
uniform mat4 m_model;
uniform mat3 m_normal;
uniform SceneLighting scene_lighting;

void main ()
{
  texCoords = inTexCoords;
  // ambient
  vec3 amb = scene_lighting.ambient.xyz * scene_lighting.ambient.w;
  // diffuse
  // [FIXME] normal matrix
  // mat3 norm_mat = mat3(transpose(inverse(m_model)));
  vec3 light_dir = normalize(scene_lighting.light_pos - inPos);
  vec3 norm = m_normal * inNormal;
  float diff = max(dot(norm, light_dir), 0);
  // color
  vColor = (amb + diff) * inColor;
  //
  gl_Position = m_proj * m_model * vec4(inPos, 1.f);
}
